package com.hhz.swagger.controller;

import com.hhz.swagger.pojo.User;
import com.hhz.swagger.server.UserService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author Rem
 * @Date 2019-08-02
 * @Version 1.0
 */

@Api(tags = "用户管理", value = "用户管理2222", produces = "application/json")
@CrossOrigin
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 增
     *
     * @param user
     */
    @ApiOperation(value = "添加用户", notes = "添加用户2222")
    @ApiImplicitParam(paramType = "query", name = "user", value = "用户实体", required = true, dataType = "user")
    @PostMapping("/addUser")
    public User addUser(@RequestBody User user) {
        return userService.addUser(user);
    }

    /**
     * 删
     *
     * @param id
     */
    @ApiOperation(value = "删除用户", notes = "删除用户2222")
    @DeleteMapping(value = "/delUser/{id}")
    @ApiImplicitParam(name = "id", value = "用户id", required = true, paramType = "path", dataType = "Integer")
    public void delUser(@PathVariable Integer id) {
        userService.delUser(id);
    }


    /**
     * 改
     *
     * @param user
     */
    @ApiOperation(value = "更新用户", notes = "更新用户2222")
    @ApiImplicitParam(paramType = "query", name = "user", value = "用户实体", required = true, dataType = "user")
    @PutMapping(value = "/updateUser")
    public void updateUser(@RequestBody User user) {
        userService.updateUser(user);
    }

    /**
     * 根据id查
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "根据id查询用户", notes = "根据id查询用户2222")
    @ApiImplicitParam(name = "id", value = "用户id", required = true, paramType = "path", dataType = "Integer")
    @GetMapping(value = "/findById/{id}")
    public User findById(@PathVariable Integer id) {
        return userService.findById(id);
    }

    /**
     * 查全部
     *
     * @return
     */
    @ApiOperation(value = "查询全部", notes = "查询全部222")
    @GetMapping(value = "/findAll")
    public List<User> findAll() {
        return userService.findAll();
    }

    /**
     * 条件查询
     *
     * @param whereMap
     * @return
     */

    @ApiOperation(value = "条件查询", notes = "条件查询222")
    @ApiImplicitParam(paramType = "body", name = "whereMap", value = "查询map集合", required = true, dataType = "map")

    @ApiResponses({
            @ApiResponse(code = 400, message = "路径出错"),
            @ApiResponse(code = 500, message = "请求参数出错"),
    })
    @GetMapping(value = "/findSearch")
    public List<User> findSearch(@RequestBody Map whereMap) {
        return userService.findSearch(whereMap);
    }


    /**
     * 分页查询
     *
     * @param whereMap
     * @param page
     * @param size
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询222")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "whereMap", value = "查询map集合", required = true, dataType = "map"),
            @ApiImplicitParam(paramType = "path", name = "page", value = "页数", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "path", name = "page", value = "每页大小", required = true, dataType = "int")
    })
    @GetMapping(value = "/findSearch/{page}/{size}")
    public Page<User> findSearch(@RequestBody Map whereMap, @PathVariable int page, @PathVariable int size) {
        return userService.findSearch(whereMap, page, size);
    }

}
